#!/bin/bash

version=7.61.0

install_packages "https://github.com/dennisameling/Signal-Desktop/releases/download/v${version}/signal-desktop-unofficial_${version}_arm64.deb" || exit 1

#add script to run with wayland, if enabled
echo '#!/bin/bash

if [ -z "$WAYLAND_DISPLAY" ];then
  "/opt/Signal Unofficial/signal-desktop-unofficial" "$@"
else
  "/opt/Signal Unofficial/signal-desktop-unofficial" --enable-features=UseOzonePlatform --ozone-platform=wayland "$@"
fi
' | sudo tee '/opt/Signal Unofficial/signal-wayland.sh' >/dev/null
sudo chmod +x '/opt/Signal Unofficial/signal-wayland.sh'

#patch menu launcher to not say 'Signal Unofficial', and to use wayland script
sudo sed -i 's/^Name=Signal Unofficial$/Name=Signal/g ; s+/opt/Signal Unofficial/signal-desktop-unofficial+/opt/Signal Unofficial/signal-wayland.sh+g' /usr/share/applications/signal-desktop-unofficial.desktop
